
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <jsoncpp/json/json.h>
#include <string.h>
#include <iostream>

#include "log.h"

using namespace LOG;

int main()
{
    // 创建套接字
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < -1)
    {
        lg(FATAL, "socket fail");
        return 0;
    }
    // 连接服务器
    struct sockaddr_in server;
    memset(&server, 0, sizeof server);
    server.sin_addr.s_addr = inet_addr("192.168.4.3");
    server.sin_family = AF_INET;
    server.sin_port = htons(1234);
    int c = connect(sockfd, (struct sockaddr *)&server, sizeof server);
    if (c < 0)
    {
        lg(FATAL, "connect fail");
        return 0;
    }
    else
    {
        // 发送数据到服务器
        std::string outbuffer;
        std::cout << "Please Enter #";
        std::getline(std::cin, outbuffer);
        sendto(sockfd, outbuffer.c_str(), outbuffer.size(), 0, (sockaddr *)&server, sizeof(server));
    }

    return 0;
}